package com.ss.sdg.pdg;

import java.util.Vector;

import org.eclipse.jdt.core.dom.ASTNode;

/**
 * node of control flow graph
 * @author WangJie
 */
public class Node implements Comparable<Node>{

	private int nodeID;
	
	private int sdgNodeID;
	
	private String name;
	
	private ASTNode associateRoughASTNode;//rough ASTNode corresponding
	
	private ASTNode associateAccurateASTNode;//accurate ASTNode corresponding
	
	private Vector<Node> next;//next node
	
	private Vector<Node> previous;//previous node
	
	private boolean visitedFlag;//the flag that whether the node is visited or not

	public Node() {
		super();
	}

	public Node(int nodeID, String name, ASTNode associateRoughASTNode,
			ASTNode associateAccurateASTNode,boolean visitedFlag,int sdgNodeID) {
		super();
		this.nodeID = nodeID;
		this.name = name;
		this.associateRoughASTNode = associateRoughASTNode;
		this.associateAccurateASTNode = associateAccurateASTNode;
		this.visitedFlag = visitedFlag;
		
		this.next = new Vector<Node>();
		this.previous = new Vector<Node>();
		this.sdgNodeID = sdgNodeID;
	}

	public Node(int nodeID, String name, ASTNode associateRoughASTNode,
			ASTNode associateAccurateASTNode, Vector<Node> next,
			Vector<Node> previous, boolean visitedFlag) {
		super();
		this.nodeID = nodeID;
		this.name = name;
		this.associateRoughASTNode = associateRoughASTNode;
		this.associateAccurateASTNode = associateAccurateASTNode;
		this.next = next;
		this.previous = previous;
		this.visitedFlag = visitedFlag;
	}

	public int getNodeID() {
		return nodeID;
	}

	public void setNodeID(int nodeID) {
		this.nodeID = nodeID;
	}

	public int getSdgNodeID() {
		return sdgNodeID;
	}

	public void setSdgNodeID(int sdgNodeID) {
		this.sdgNodeID = sdgNodeID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ASTNode getAssociateRoughASTNode() {
		return associateRoughASTNode;
	}

	public void setAssociateRoughASTNode(ASTNode associateRoughASTNode) {
		this.associateRoughASTNode = associateRoughASTNode;
	}

	public ASTNode getAssociateAccurateASTNode() {
		return associateAccurateASTNode;
	}

	public void setAssociateAccurateASTNode(ASTNode associateAccurateASTNode) {
		this.associateAccurateASTNode = associateAccurateASTNode;
	}

	public Vector<Node> getNext() {
		return next;
	}

	public void setNext(Vector<Node> next) {
		this.next = next;
	}

	public Vector<Node> getPrevious() {
		return previous;
	}

	public void setPrevious(Vector<Node> previous) {
		this.previous = previous;
	}

	public boolean isVisitedFlag() {
		return visitedFlag;
	}

	public void setVisitedFlag(boolean visitedFlag) {
		this.visitedFlag = visitedFlag;
	}
	/**
	 * add node into next
	 * @param node
	 */
	public void addNext(Node node){
		this.next.add(node);
	}
	
	public int getNextCount(){
		return this.next.size();
	}
	
	public void addPrevious(Node node){
		this.previous.add(node);
	}
	
	public int getPreviousCount(){
		return this.previous.size();
	}

	@Override
	public int compareTo(Node o) {
		if (nodeID == o.nodeID) {
			return 0;
		} else if (nodeID > o.nodeID) {
			return 1;
		} else {
			return -1;
		}
	}
	
	
}
